{include file="common/mainHead"/}
<div class="admin-main fadeInUp animated">
    <blockquote class="layui-elem-quote">
        <a href="{:url('salegoods/add','catid=55')}" class="layui-btn layui-btn-small">
            <i class="fa fa-plus"></i> {:lang('add')}商品
        </a>
    </blockquote>
    <fieldset class="layui-elem-field">
        <legend>未发布商品</legend>
        <div class="layui-field-box table-responsive">
            <form class="layui-form layui-form-pane">
                <table class="layui-table table-hover">
                    <thead>
                    <tr>
                        <th>编号</th>
                        <th>名称</th>
                        <th>缩略图</th>
                        <th>开始时间</th>
                        <th>起拍价</th>
                        <th>加价幅度</th>
                        <th>保留价</th>
                        <th>当前最高</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <!--内容容器-->
                    <tbody id="con">
                    </tbody>
                    <tfoot>
                    <tr>
                        <td colspan="8">
                            <!--分页容器-->
                            <div id="paged" style="text-align: right"></div>
                        </td>
                    </tr>
                    </tfoot>
                </table>
            </form>
        </div>
    </fieldset>
</div>
<!--模板-->
<script type="text/html" id="conTemp">
    {{# layui.each(d.list, function(index, item){ }}
    <tr>
        <td>{{ item.id }}</td>
        <td>{{ item.title }}</td>
        <td><img src="__PUBLIC__/{{ item.thumb }}" style="width: 60px;height: 60px;"></td>
        <td>{{ getdate(item.starttime)}}</td>
        <td>{{ item.startprice }}</td>
        <td>{{ item.marupprice }}</td>
        <td>{{ item.endprice }}</td>
        <td>
            {{# if(!item.maxprice){ }}
                ￥0
            {{# }else{  }}
                ￥{{ item.maxprice }}
            {{# } }}
        </td>
        <td>
            {{# if(item.status==1){ }}
            <a class="red" href="javascript:" onclick="return stateyes('{{ item.id }}');" title="已发布">
                <div id="zt{{ item.id }}">
                    <button class="layui-btn layui-btn-warm layui-btn-mini">已发布</button>
                </div>
            </a>
            {{# }else{  }}
            <a class="red" href="javascript:" onclick="return stateyes('{{ item.id }}');" title="已撤回">
                <div id="zt{{ item.id }}">
                    <button class="layui-btn layui-btn-danger layui-btn-mini">已撤回</button>
                </div>
            </a>
            {{# } }}
        </td>
        <td>
            <a href="{:url('salegoods/edit')}?id={{item.id}}" class="layui-btn layui-btn-mini">{:lang('edit')}</a>
            <a href="javascript:;" onclick="return del({{item.id}})" data-id="1" data-opt="del" class="layui-btn layui-btn-danger layui-btn-mini">删除</a>
        </td>
    </tr>
    {{# }); }}
</script>
{include file="common/mainFoot"/}
<script>
        layui.config({
        base: '__ADMIN__/js/'
    }).use(['paging', 'code','icheck','layer'], function() {
        layui.code();
        var paging = layui.paging(),layer = parent.layer === undefined ? layui.layer : parent.layer;
        paging.init({
            url: "{:url('unpublish')}", //地址
            elem: '#con', //内容容器
            params: {}, //发送到服务端的参数
            tempElem: '#conTemp', //模块容器
            pageConfig: { //分页参数配置
                elem: '#paged', //分页容器
                pageSize: 15 //分页大小
            },
            success: function() { //渲染成功的回调
                //alert('渲染成功');
            },
            fail: function(msg) { //获取数据失败的回调
                //alert('获取数据失败')
            },
            complate: function() { //完成的回调
                //alert('处理完成');
            }
        });
    });
        function getdate(date){
            var date = new Date(date*1000);//如果date为10位不需要乘1000
            var Y = date.getFullYear() + '-';
            var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
            var D = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate()) + ' ';
            var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var m = (date.getMinutes() <10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var s = (date.getSeconds() <10 ? '0' + date.getSeconds() : date.getSeconds());
            return Y+M+D+h+m+s;
        }

        function stateyes(id) {
            $.post('{:url("goodsState")}', {id: id}, function (data) {
                if (data.status) {
                    if (data.info == '已撤回') {
                        var a = '<button class="layui-btn layui-btn-danger layui-btn-mini">已撤回</button>'
                        $('#zt' + id).html(a);
                        layer.msg(data.info, {icon: 5});
                        return false;
                    } else {
                        var b = '<button class="layui-btn layui-btn-warm layui-btn-mini">已发布</button>'
                        $('#zt' + id).html(b);
                        layer.msg(data.info, {icon: 6});
                        return false;
                    }
                }else{
                    layer.msg(data.msg,{time:1000,icon:2});
                    return false;
                }
            });
            return false;
        }


        function del(id) {
        layer.confirm('你确定要删除吗？', {icon: 3}, function (index) {
            layer.close(index);
            window.location.href = "{:url('delGoods')}?id=" + id;
        });
    }
</script>